package yunquan.wang.base.domain;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.domain.Persistable;

/**
 * 统一定义id的entity基类.
 * 
 * 基类统一定义id的属性名称、数据类型、列名映射及生成策略. 子类可重载getId()函数重定义id的列名映射和生成策略.
 * 
 */
// JPA Entity基类的标识
@MappedSuperclass
public abstract class  IdEntity implements Persistable<String> {

    private static final long serialVersionUID = 4135637827653249198L;
    @Id
    @Column(unique=true,length=36,name="ID")
    @GeneratedValue(generator = "UIDGenerator")
    @GenericGenerator(name = "UIDGenerator", strategy = "uuid2")
    protected String id;
    
    @Version
    private java.sql.Timestamp timestamp;
    
     public String getId() {
	return id;
    }

    public void setId(String id) {
	this.id = id;
    }

	public java.sql.Timestamp getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(java.sql.Timestamp timestamp) {
		this.timestamp = timestamp;
	}
public	boolean isNew()
	{
		return StringUtils.isBlank(id);
	}
}
